<div class="layui-fluid">
  <div class="layui-row">
    <form action="" method="post" class="layui-form layui-form-pane">
      <div class="layui-form-item">
        <label for="password" class="layui-form-label">
          <span class="x-red">*</span>新密码
        </label>
        <div class="layui-input-inline">
          <input type="password" id="password" name="password" required="" lay-verify="required|pass" autocomplete="off"
            class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="password2" class="layui-form-label">
          <span class="x-red">*</span>再次输入密码
        </label>
        <div class="layui-input-inline">
          <input type="password" id="password2" name="password2" required="" lay-verify="required|pass" autocomplete="off"
            class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <button class="layui-btn" lay-submit="" lay-filter="save">保存</button>
      </div>
    </form>
  </div>
</div>
<script>
  layui.use(['form', 'layer'], function () {
    $ = layui.jquery;
    var form = layui.form
      , layer = layui.layer;

    //监听提交
    form.on('submit(save)', function (data) {
      //发异步，把数据提交给php
      if (data.field.password === data.field.password2) {
        main.ajaxPost(
          {
            url: "{:url('password')}",
            data: data.field,
          },
          function (data) {
            setTimeout(function () {
              //关闭当前frame 
              parent.layer.closeAll();
            }, 1000);
          }
        )
      } else {
        layer.msg('两次输入的密码不一致！');
      }
      return false;
    });
  });
</script>